import {createRouter,createWebHistory} from 'vue-router'
//导入对应组件
import LoginVue from '@/views/Login.vue'
import LayoutVue from '@/views/Layout.vue'

import ArticleCategoryVue from '@/views/article/family.vue'
import ArticleManageVue from '@/views/article/ArticleManage.vue'
import UserInfoVue from '@/views/user/UserInfo.vue'
import UserResetPasswordVue from '@/views/user/UserResetPassword.vue'
import loanVue from '@/views/article/loan.vue'
import BabyVue from '@/views/article/baby.vue'
import LandVue from '@/views/article/land.vue'
import HomeVue from '@/views/user/home.vue'
//定义路由关系 component:路径访问之后展示对应的组件 
//主页下多个菜单栏children子路由 是个数组多个js对象 redirect重定向访问/时默认哪个路径

const routes = [
    {path:'/login',component:LoginVue},
    {path:'/',component:LayoutVue,redirect:'/user/home',children:[
        {path:'/user/home',component:HomeVue},
        {path:'/article/family',component:ArticleCategoryVue},
        {path:'/article/loan',component:loanVue},
        {path:'/article/baby',component:BabyVue},
        {path:'/article/land',component:LandVue},
        {path:'/user/info',component:UserInfoVue},
        {path:'/user/resetPassword',component:UserResetPasswordVue},
    ]}
]

// 替换原来的直接导入
// const routes = [
//     { 
//         path: '/login', 
//         component: () => import('@/views/Login.vue') // 懒加载
//     },
//     { 
//         path: '/', 
//         component: () => import('@/views/Layout.vue'), // 懒加载
//         redirect: '/article/family',
//         children: [
//             { path: '/article/family', component: () => import('@/views/article/family.vue') },
//             { path: '/article/manage', component: () => import('@/views/article/ArticleManage.vue') },
//             { path: '/user/info', component: () => import('@/views/user/UserInfo.vue') },
//             { path: '/user/avator', component: () => import('@/views/user/UserAvatar.vue') },
//             { path: '/user/resetPassword', component: () => import('@/views/user/UserResetPassword.vue') },
//         ]
//     }
// ]
//创建路由器 {}里传递一个js对象
const router = createRouter({
    history:createWebHistory(),
    routes:routes//传递路由关系
})

//导出路由
export default router